package com.rankeiot.platform.domain;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.sql.Types;

import com.rankeiot.core.data.MenuItem;
import lombok.Data;
import lombok.experimental.FieldNameConstants;
import io.swagger.v3.oas.annotations.media.Schema;
import org.sagacity.sqltoy.config.annotation.Entity;
import org.sagacity.sqltoy.config.annotation.Id;
import org.sagacity.sqltoy.config.annotation.Column;
import jakarta.validation.constraints.NotNull;
import org.hibernate.validator.constraints.Length;


/**
 * 系统菜单
 */
@Schema(description="系统菜单")
@Data
@FieldNameConstants(asEnum = true)
@Entity(tableName=Menu.TABLE)
public class Menu implements Serializable{
    public static final String TABLE="t_menu";

    /**
     * 所属分组
     */
    @Schema(description="所属分组")
    @Id
    @Length(max=5)
    @Column(name="menu_group",length=5L,type=Types.VARCHAR)
    private String menuGroup;
    /**
     * id
     */
    @Schema(description="id")
    @Id
    @Length(max=100)
    @Column(name="id",length=100L,type=Types.VARCHAR,nullable=false)
    private String id;

    /**
     * 标题
     */
    @Schema(description="标题")
    @Length(max=255)
    @Column(name="title",length=255L,type=Types.VARCHAR)
    private String title;
    /**
     * 父级菜单
     */
    @Schema(description="父级菜单")
    @Length(max=100)
    @Column(name="parent",length=100L,type=Types.VARCHAR)
    private String parent;
    /**
     * 排序
     */
    @Schema(description="排序")
    @Column(name="sort",length=10L,type=Types.INTEGER)
    private int sort;
    /**
     * 路径
     */
    @Schema(description="路径")
    @Length(max=100)
    @Column(name="path",length=100L,type=Types.VARCHAR)
    private String path;
    /**
     * 图标
     */
    @Schema(description="图标")
    @Length(max=50)
    @Column(name="icon",length=50L,type=Types.VARCHAR)
    private String icon;
    /**
     * 类型:菜单/权限
     */
    @Schema(description="类型:菜单/权限")
    @Column(name="menu_type",length=10L,type=Types.INTEGER)
    private Integer menuType;

    /**
     * 是否启用
     */
    @Schema(description="是否启用")
    @Column(name="enable",length=3L,type=Types.TINYINT)
    private Boolean enable;
    /**
     * 是否为系统菜单
     */
    @Schema(description="是否为系统菜单")
    @Column(name="`system`",length=3L,type=Types.TINYINT)
    private Boolean system;

    public Menu(){}
    public Menu(String id,String menuGroup){
        this.menuGroup=menuGroup;
        this.id=id;
    }

    public MenuItem createItem(){
        MenuItem item = new MenuItem();
        item.setKey(getId());
        item.setTitle(getTitle());
        item.setType(getMenuType());
        item.setParent(getParent());
        item.setEnable(getEnable());
        item.setSystem(getSystem());
        item.setOrder(getSort());
        item.setPath(getPath());
        item.setIcon(getIcon());
        return item;
    }

    /**
     * 填充
     * @param it
     */
    public void fillItem(MenuItem it){
        setId(it.getKey());
        setParent(it.getParent());
        setMenuType(it.getType());
        setSystem(it.isSystem());
        setPath(it.getPath());
        setTitle(it.getTitle());
        setIcon(it.getIcon());
        setEnable(it.isEnable());
        setSort(it.getOrder());
    }
}
